package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.opcode_3593_ACK;
import ru.pb.game.objects.model.players.Player;
import ru.pb.game.objects.model.room.Room;
import ru.pb.game.objects.storage.ObjectsStorage;

/**
 * Чтение пароля в комнате
 * 
 * @author Felixx
 */
public class opcode_3593_REQ extends FromClientToGameServerPacket
{
	/**
	 * Чтение пароля в комнате
	 */
	public opcode_3593_REQ()
	{}

	private String _pass;

	@Override
	public void readImpl()
	{
		readH(); // Frost
		_pass = readS(4);
	}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			Room r = p.getRoom();
			r.password = _pass;
			Player member = null;
			for(int objId : r.getAllPlayers().toArray())
			{
				member = ObjectsStorage.getInstance().getPlayer(objId);
				member.sendPacket(new opcode_3593_ACK(r));
			}
		}
	}
}